
$(document).ready(function(){
    $(".email-show").click(function () {
        $(this).toggleClass("email-show-stop") ;
    }) ;
    $(".cur-user").click(function () {
        $(".trun-out").toggleClass("roteYhidden") ;
        $(".logout").toggleClass("roteYhidden") ;
    }) ;
    $(".moon-font").lzhDrag({
        startDown: function () {
        },
        startMove: function () {
        },
        overMove: function () {
        }
    }).html("");
    $(".moon-font").mousemove(function(e){
        e = e || window.event;
        let cur_top = getDistance($(this)).top ,
            cur_right = getDistance($(this)).right ;
        let min_x=0,max_x=140,
            min_y=0,max_y=140;
        cur_right = cur_right<min_x ? min_x : cur_right ;
        cur_right = cur_right>max_x ? max_x : cur_right ;
        cur_top = cur_top<min_y ? min_y : cur_top ;
        cur_top = cur_top>max_y ? max_y : cur_top ;
        var target_x=40 , target_y=40 ;
        var curDis= (cur_right-target_x)*(cur_right-target_x) + (cur_top-target_y)*(cur_top-target_y) ;
        var rate=1-curDis/20000 ;
        rate*=0.9 ;
        if (rate>=0.7) {
            $(".article-main").addClass("box-higher") ;
            $(".article-main h3").addClass("h2-light") ;
            $(".article-main h2").addClass("h2-light") ;
            $(".article-main h1").addClass("h2-light") ;
            $(".hljs").addClass("hljs-bg") ;
        } else {
            $(".article-main").removeClass("box-higher") ;
            $(".article-main h3").removeClass("h2-light") ;
            $(".article-main h2").removeClass("h2-light") ;
            $(".article-main h1").removeClass("h2-light") ;
            $(".hljs").removeClass("hljs-bg") ;
        }
        /*console.log(curDis) ;
        console.log(rate) ;
        console.log(cur_right+":"+cur_top) ;*/
        var curLightness="5000px solid rgba(0, 0, 0,"+rate+")" ;
        $(".lightCover").css("outline",curLightness) ;
    });
    $(".moon-back").click(function () {
        startSakura() ;
    }) ;
    $(".fake-info").click(function () {
        $(".fake-info").css("display","none") ;
    }) ;
    $(".cur-user").click(function () {
        $(".moon-light").toggleClass("moon-hidden") ;
        $(".moon-back").toggleClass("moon-hidden") ;
        $(".moon-font").toggleClass("moon-hidden") ;
    }) ;
    $(window).scroll(function () {
        let totHeight = document.body.scrollHeight-window.innerHeight ;
        let curRate = ($(document).scrollTop() / totHeight) *100;
        var tmp = curRate.toString()+"%" ;
        $("#preogressbar").css("height",tmp) ;
    }) ;
}) ;
function getDistance(obj) {
    if (!obj instanceof jQuery) {
        obj = $(obj);
    }
    var distance = {};
    distance.top = (obj.offset().top - $(document).scrollTop());
    distance.bottom = ($(window).height() - distance.top - obj.outerHeight());
    distance.left = (obj.offset().left - $(document).scrollLeft());
    distance.right = ($(window).width() - distance.left - obj.outerWidth());
    return distance;
}
$.fn.extend({
    lzhDrag: function (obj) {
        let max_left = $(this).offsetParent().outerWidth() - $(this).outerWidth(),
            max_top = $(this).offsetParent().outerHeight() - $(this).outerHeight();
        $(this).on('mousedown', event => {
            let ele_x = event.offsetX,
                ele_y = event.offsetY;
            obj.startDown && obj.startDown();
            $(document).on('mousemove', e => {
                obj.startMove && obj.startMove();
                e.preventDefault();
                let left = e.clientX - ele_x,
                    top = e.clientY - ele_y;
                left = left < 0 ? 0 : left;
                top = top < 0 ? 0 : top;
                left = left > max_left ? max_left : left;
                top = top > max_top ? max_top : top;
                $(this).css({
                    left, top
                })
            })
        })
        $(document).on('mouseup', () => {

            $(document).off('mousemove');
            obj.overMove && obj.overMove();
        })
        return this;
    }
})
